﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TreeViewHelper.Mvc.Demo.Models
{
    public class ProductCategory
    {
        public int ProductCategoryId { get; set; }

        public string ProductCategoryName { get; set; }

        public string ProductCategoryDescription { get; set; }

        public static List<ProductCategory> GetAll()
        {
            List<ProductCategory> categories = new List<ProductCategory>();
            categories.Add(new ProductCategory() { ProductCategoryId = 1, ProductCategoryName = "Electronics" });
            categories.Add(new ProductCategory() { ProductCategoryId = 2, ProductCategoryName = "Vehicles" });
            categories.Add(new ProductCategory() { ProductCategoryId = 3, ProductCategoryName = "Furniture" });
            categories.Add(new ProductCategory() { ProductCategoryId = 4, ProductCategoryName = "Clothes" });
            categories.Add(new ProductCategory() { ProductCategoryId = 5, ProductCategoryName = "Computers" });
            categories.Add(new ProductCategory() { ProductCategoryId = 6, ProductCategoryName = "Mobiles" });
            categories.Add(new ProductCategory() { ProductCategoryId = 7, ProductCategoryName = "Accessories" });
            categories.Add(new ProductCategory() { ProductCategoryId = 8, ProductCategoryName = "Bluetooth" });
            categories.Add(new ProductCategory() { ProductCategoryId = 9, ProductCategoryName = "Handsfree" });
            return categories;
        }        
    }

    public class ProductCategoryLevel
    {
        public int ProductCategoryLevelId { get; set; }

        public int ProductCategoryId { get; set; }

        public int ParentProductCategoryId { get; set; }

        public ProductCategory ProductCategory { get; set; }

        public ProductCategory ParentProductCategory { get; set; }

        public static List<ProductCategoryLevel> GetAll()
        {
            List<ProductCategoryLevel> categoryLevels = new List<ProductCategoryLevel>();
            categoryLevels.Add(new ProductCategoryLevel() { ProductCategoryLevelId = 1, ProductCategoryId = 1, ParentProductCategoryId = 1 });
            categoryLevels.Add(new ProductCategoryLevel() { ProductCategoryLevelId = 2, ProductCategoryId = 2, ParentProductCategoryId = 2 });
            categoryLevels.Add(new ProductCategoryLevel() { ProductCategoryLevelId = 3, ProductCategoryId = 3, ParentProductCategoryId = 3 });
            categoryLevels.Add(new ProductCategoryLevel() { ProductCategoryLevelId = 4, ProductCategoryId = 4, ParentProductCategoryId = 4 });
            categoryLevels.Add(new ProductCategoryLevel() { ProductCategoryLevelId = 5, ProductCategoryId = 5, ParentProductCategoryId = 1 });
            categoryLevels.Add(new ProductCategoryLevel() { ProductCategoryLevelId = 6, ProductCategoryId = 6, ParentProductCategoryId = 1 });
            categoryLevels.Add(new ProductCategoryLevel() { ProductCategoryLevelId = 7, ProductCategoryId = 7, ParentProductCategoryId = 6 });
            categoryLevels.Add(new ProductCategoryLevel() { ProductCategoryLevelId = 8, ProductCategoryId = 8, ParentProductCategoryId = 7 });
            categoryLevels.Add(new ProductCategoryLevel() { ProductCategoryLevelId = 9, ProductCategoryId = 9, ParentProductCategoryId = 7 });

            foreach (ProductCategoryLevel categoryLevel in categoryLevels)
            {
                categoryLevel.ProductCategory = ProductCategory.GetAll().Where(m => m.ProductCategoryId.Equals(categoryLevel.ProductCategoryId)).FirstOrDefault();
                categoryLevel.ParentProductCategory = ProductCategory.GetAll().Where(m => m.ProductCategoryId.Equals(categoryLevel.ParentProductCategoryId)).FirstOrDefault();
            }

            return categoryLevels;
        }
    }
}